import {reqCategoryList,reqGetBannerList,reqFloorList} from '@/api'

const state ={
    categoryList:[],
    bannerList:[],
    floorList:[],
};
//mutations :修改state的唯一手段
const mutations ={
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList;
    },
    CATEBANNERLIST(state,bannerList){
        state.bannerList = bannerList;
    },
    CATEFLOORLIST(state,floorList){
        state.floorList = floorList;
    }
};
//actions:处理action,可以书写自己的业务逻辑,也可以处理异步
const actions ={
    //通过API里面的接口函数调用,向服务器发送请求,获取服务器的数据
    async categoryList({commit}){
        let result = await reqCategoryList();
        if(result.code ==200){
            commit('CATEGORYLIST',result.data)
        }
    },
    //获取首页轮播图的数据
    async getBannerList({commit}){
       let result = await reqGetBannerList();
       console.log(result);
       if(result.code === 200){
           commit('CATEBANNERLIST',result.data)
       }
    },
    //获取floor的数据
    async getFloorList({commit}){
        let result =  await reqFloorList();
        if(result.code == 200){
            commit('CATEFLOORLIST',result.data);
        }
    }
};
//getters:理解为计算属性,用于简化仓库数据,让组件获取仓库的数据更加方便
const getters ={};

//对外暴露store类的一个实例
export default{
      state,
      mutations,
      actions,
      getters
}